package Utils 
{
	import flash.events.Event;
	import flash.net.URLVariables;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	
	/**
	 * ...
	 * @author Victor Cruz
	 */
	public class Server 
	{
		private static var dataPass:URLVariables;
		private static var urlLoader:URLLoader = new URLLoader();
		private static var xml:XML;
		
		public function Server() 
		{
			
		}
		/**
		 * Send the xml to server
		 */
		public static function SendXML(xml:String, requestType:String)
		{
			var request:URLRequest = new URLRequest(Constants.SERVER_PATH);
			request.method = URLRequestMethod.POST;
			
			dataPass = new URLVariables();
			dataPass.xml = xml;
			dataPass.requestType = requestType;
			
			request.data = dataPass;
			
			
			
			urlLoader.load(request);
		}
		
		public static function RequestXmlFromServer():void
		{
			var request:URLRequest = new URLRequest(Constants.SERVER_PATH);
			request.method = URLRequestMethod.POST;
			
			dataPass = new URLVariables();
			dataPass.requestType = RequestType.SELECT_PLAYER;
			
			request.data = dataPass;
			
			urlLoader.load(request);
			urlLoader.addEventListener(Event.COMPLETE, completeRequest);
		}
		
		private static function completeRequest(e:Event)
		{
			xml = new XML(urlLoader.data);
		}
		
		public static function getXMl():XML
		{
			return xml;
		}
	}
}